using System;
using System.Collections.Generic;
using System.Text;
using Barrage.GUI;
using Spacedash.Logic;
using Barrage.GUI.Elements;
using Barrage.Language;

namespace Spacedash.Game.Subgames
{
    sealed class RaceResumeElements
    {
        public const string NextButton = "NEXT_BUTTON";
        public const string RecordText = "RECORD_TEXT";
    }
    class RaceResumeSection : GUISection
    {
        const string NAME = "NAME";
        const string BEST_LAP = "BEST_LAP";
        public override int Id
        {
            get { return (int)GameState.RaceResume; }
        }
        public RaceResumeSection(Race race,SpacedashGame parent)
            : base("RaceResume", parent)
        {
            string resumeText = String.Format("# / {0,14} / {1,20}\n",LanguageManager.Texts["NAME"],LanguageManager.Texts["BEST_LAP"]);
            resumeText += "------------------------\n";
            foreach (KeyValuePair<int,Ship> ship in race.OrderedShips)
            {
                resumeText += String.Format("{0} / {1,14} / ", ship.Key, ship.Value.Profile.Name);
                Lap best = ship.Value.BestLap;
                if (best.time != 0)
                    resumeText += best;
                resumeText += "\n";
            }

            ((GUIText)Layout.Elements[RaceResumeElements.RecordText]).Text = resumeText;
            RegisterButtonEvent(RaceResumeElements.NextButton, new GUIButtonHandler(NextButtonClick));
        }

        public void NextButtonClick(string buttonId)
        {
            Parent.NextGameSectionId = (int)GameState.MainMenu;
        }
        
    }
}
